home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / lib / stdio / io.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-07  |  4.4 KB  |  165 lines

  1. /* @(#)io.h    2.10 00/05/07 Copyright 1986, 1995 J. Schilling */
  2. /*
  3.  *    Copyright (c) 1986, 1995 J. Schilling
  4.  */
  5. /*
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; see the file COPYING.  If not, write to
  18.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <mconfig.h>
  22. #include <standard.h>
  23. #include <unixstd.h>
  24. #include <fctldefs.h>
  25. #include <schily.h>
  26.  
  27. #ifdef    NO_USG_STDIO
  28. #    ifdef    HAVE_USG_STDIO
  29. #        undef    HAVE_USG_STDIO
  30. #    endif
  31. #endif
  32.  
  33. /*
  34.  * speed things up...
  35.  */
  36. #define    _openfd(name, omode)    (open(name, omode, 0666))
  37.  
  38. #define    DO_MYFLAG        /* use local flags */
  39.  
  40. /*
  41.  * Flags used during fileopen(), ... by _fcons()/ _cvmod()
  42.  */
  43. #define    FI_NONE        0x0000    /* no flags defined */
  44.  
  45. #define    FI_READ        0x0001    /* open for reading */
  46. #define    FI_WRITE    0x0002    /* open for writing */
  47. #define    FI_BINARY    0x0004    /* open in binary mode */
  48.  
  49. #define    FI_CREATE    0x0010    /* create if nessecary */
  50. #define    FI_TRUNC    0x0020    /* truncate file on open */
  51. #define    FI_APPEND    0x0040    /* append on each write */
  52. #define    FI_UNBUF    0x0080    /* dont't buffer io */
  53. #define    FI_CLOSE    0x1000    /* close file on error */
  54.  
  55. /*
  56.  * local flags
  57.  */
  58. #define    _IONORAISE    01    /* do no raisecond() on errors */
  59. #define    _IOUNBUF    02    /* do unbuffered i/o */
  60.  
  61. #ifdef    DO_MYFLAG
  62.  
  63. struct _io_flags {
  64.     FILE    *fl_io;        /* file pointer */
  65.     struct _io_flags    /* pointer to next struct */
  66.         *fl_next;    /* if more file pointer to same fd */
  67.     int    fl_flags;    /* my flags */
  68. };
  69.  
  70. typedef    struct _io_flags _io_fl;
  71.  
  72. extern    int    _io_glflag;    /* global default flag */
  73. extern    _io_fl    *_io_myfl;    /* array of structs to hold my flags */
  74. extern    int    _fl_max;    /* max fd currently in _io_myfl */
  75.  
  76. /*
  77.  *    if fileno > max
  78.  *        expand
  79.  *    else if map[fileno].pointer == 0
  80.  *        return 0
  81.  *    else if map[fileno].pointer == p
  82.  *        return map[fileno].flags
  83.  *    else
  84.  *        search list
  85.  */
  86. #define    flp(p)        (&_io_myfl[fileno(p)])
  87.  
  88. #ifdef    MY_FLAG_IS_MACRO
  89. #define    my_flag(p)    ((int)fileno(p) >= _fl_max ?            \
  90.                 _io_get_my_flag(p) :            \
  91.             ((flp(p)->fl_io == 0 || flp(p)->fl_io == p) ?    \
  92.                 flp(p)->fl_flags :            \
  93.                 _io_get_my_flag(p)))
  94. #else
  95. #define    my_flag(p)    _io_get_my_flag(p)
  96. #endif
  97.  
  98. #define    set_my_flag(p,v) _io_set_my_flag(p, v)
  99. #define    add_my_flag(p,v) _io_add_my_flag(p, v)
  100.  
  101. extern    int    _io_get_my_flag __PR((FILE *));
  102. extern    void    _io_set_my_flag __PR((FILE *, int));
  103. extern    void    _io_add_my_flag __PR((FILE *, int));
  104.  
  105. #else    /* DO_MYFLAG */
  106.  
  107. #define    my_flag(p)        _IONORAISE    /* Always noraise */
  108. #define    set_my_flag(p,v)            /* Ignore */
  109. #define    add_my_flag(p,v)            /* Ignore */
  110.  
  111. #endif    /* DO_MYFLAG */
  112.  
  113. #ifdef    HAVE_USG_STDIO
  114. /*
  115.  * Define prototypes to verify if our interface is right
  116.  */
  117. extern    int    _filbuf    __PR((FILE *));
  118. extern    int    _flsbuf    __PR((int, FILE *));
  119. #else
  120. /*
  121.  * If we are on a non USG system we cannot down file pointers
  122.  */
  123. #undef    DO_DOWN
  124. #endif
  125.  
  126. #ifndef    DO_DOWN
  127. /*
  128.  *    No stream checking
  129.  */
  130. #define    down(f)
  131. #define    down1(f,fl1)
  132. #define    down2(f,fl1,fl2)
  133. #else
  134. /*
  135.  *    Do stream checking (works only on USG stdio)
  136.  *
  137.  *    New version of USG stdio.
  138.  *    _iob[] holds only a small amount of pointers.
  139.  *    Aditional space is allocated.
  140.  *    We may check only if the file pointer is != NULL
  141.  *    and if iop->_flag refers to a stream with appropriate modes.
  142.  *    If _iob[] gets expanded by malloc() we cannot check upper bound.
  143.  */
  144. #define down(f)        ((f) == 0 || (f)->_flag==0 ? \
  145.                 (raisecond(_badfile, 0L),(FILE *)0) : (f))
  146.  
  147. #define down1(f,fl1)    ((f) == 0 || (f)->_flag==0 ? \
  148.                     (raisecond(_badfile, 0L),(FILE *)0) : \
  149.                 (((f)->_flag & fl1) != fl1 ? \
  150.                     (raisecond(_badop, 0L),FILE *)0) : \
  151.                     (f)))
  152.  
  153. #define down2(f,fl1,fl2)((f) == 0 || (f)->_flag==0 ? \
  154.                 (raisecond(_badfile, 0L),(FILE *)0) : \
  155.             (((f)->_flag & fl1) != fl1 && \
  156.              ((f)->_flag & fl2) != fl2 ? \
  157.                 (raisecond(_badop, 0L),(FILE *)0) : \
  158.                 (f)))
  159. #endif    /* DO_DOWN */
  160.  
  161. extern    char    _badfile[];
  162. extern    char    _badmode[];
  163. extern    char    _badop[];
  164.  
  165.